package com.renhe.service.impl;

import com.renhe.mapper.CustomerMapper;
import com.renhe.pojo.Count;
import com.renhe.pojo.Customer;
import com.renhe.pojo.QueryVo;
import com.renhe.service.CustomerService;
import com.renhe.utils.EasyUIResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhanglei on 2017/8/15.
 */
@Service
public class CustomerServiceImpl implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    public Count getCount(QueryVo queryVo) {
        Count count = customerMapper.getCount(queryVo);
        return count;
    }

    public EasyUIResult getCustomerList(QueryVo queryVo) {
        //分页
        if (queryVo.getPage() != null) {
            queryVo.setStart((queryVo.getPage()-1)*queryVo.getRows());
        }

        List<Customer> customerList = customerMapper.getCustomerList(queryVo);
        int total = customerMapper.getCustomerTotal(queryVo);

        EasyUIResult easyUIResult = new EasyUIResult(total, customerList);
        return easyUIResult;
    }

}
